/// @tags: EulerCiruit
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

namespace BlueQuantum {

typedef long long LL;

int const N = 2e3 + 5e2 + 5;

struct Edge {
  int u, v, w;
  Edge(int u, int v, int w) : u(u), v(v), w(w){};
  inline bool operator<(Edge const &rhs) const { return w < rhs.w; }
};

int fa[N], bel[N], sum, deg[N];

int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }

inline void init(int n) {
  for (int i = 1; i <= n; ++i) fa[i] = i;
}

inline int main() {
  int n, m, s;
  cin >> n >> m >> s;
  init(n);
  for (int i = 1, u, v; i <= m; ++i) {
    cin >> u >> v;
    deg[u]++, deg[v]++;
    sum += abs(u - v);
    fa[find(u)] = find(v);
  }
  for (int i = 1; i <= n; ++i) bel[i] = find(i);
  for (int i = 1; i <= n; ++i) {
    init(n);
    deg[s]++, deg[i]++;
    fa[find(bel[s])] = find(bel[i]);
    LL ans = sum, pre = 0;
    for (int j = 1; j <= n; ++j)
      if (deg[j] & 1) {
        if (pre) {
          ans += j - pre;
          for (int k = pre; k < j; ++k) fa[find(bel[k])] = fa[find(bel[j])];
          pre = 0;
        } else
          pre = j;
      }
    vector<Edge> e;
    for (int j = 1; j <= n; ++j)
      if (deg[j]) {
        if (pre && find(bel[j]) != find(bel[pre]))
          e.push_back(Edge(bel[j], bel[pre], abs(j - pre)));
        pre = j;
      }
    sort(e.begin(), e.end());
    for (vector<Edge>::iterator j = e.begin(), jlim = e.end(); j != jlim; ++j)
      if (find(j->u) != find(j->v)) fa[find(j->u)] = find(j->v), ans += j->w * 2;
    deg[s]--, deg[i]--;
    cout << ans << ' ';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P6628 [省选联考 2020 B 卷] 丁香之路.in", "r", stdin);
  freopen("P6628 [省选联考 2020 B 卷] 丁香之路.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
